import request from '@/router/axios'
import moment from 'moment';
import {
  getMappingStatus,
  fenExYuangettoFixed,
  getLineName,
  getStationName,
  getMappingStatusArray,
  getNewMappingStatusArray, allStatus,
  xieChaStatus,
  getXieChaStatusFormat,
  getRepalceStatus,
  repalceStatus,
} from "../subwayRat/commonCheck";

export function get_xw_SwAuTvmCashAmountHierarchyDifferenceList(param) {
  return request({
    url: '/check/checkNew/get_xw_SwAuTvmCashAmountHierarchyDifferenceList',
    method: 'post',
    data: param,
    params: param
  })
}
export function updateSwAuTvmCashAmountHierarchyDifferenceToHK(param) {
  return request({
    url: '/check/checkNew/updateSwAuTvmCashAmountHierarchyDifferenceToHK',
    method: 'post',
    data: param,
    params: param
  })
}
export function updateSwAuTvmCashAmountHierarchyDifferenceToHKBF(param) {
  return request({
    url: '/check/checkNew/updateSwAuTvmCashAmountHierarchyDifferenceToHKBF',
    method: 'post',
    data: param,
    params: param
  })
}
export function updateSwAuTvmCashAmountHierarchyDifference(param) {
  return request({
    url: '/check/checkNew/updateSwAuTvmCashAmountHierarchyDifference',
    method: 'post',
    data: param,
    params: param
  })
}
/**
 * 导入
 * @param body
 */
export function importTVM(body) {
  return request({
    url: "/check/checkNew/importTVM",
    headers: { "Content-Type": "multipart/form-data" },
    method: "post",
    data: body
  });
}
/**
 * 导出
 * @param query
 */
 export function exportTVMQF(query) {
  return request({
    url: '/check/checkNew/exportTVMQF',
    method: 'get',
    params: query,
    responseType:'blob'
  })
}



export const table_XT_CJCY_Option = {
  border: true,
  index: true,
  indexLabel: '序号',
  selection: true,
  reserveSelection:false,
  stripe: true,
  menuAlign: 'center',
  viewBtn: false,
  editBtn: false,
  emptyBtn:false,
  delBtn: false,
  align: 'center',
  addBtn: false,

  column: [{label:"线路",
    "prop":"lineCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
      return getLineName(value);
    }},
    {label:"站点",
      "prop":"stationCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
        return getStationName(row.lineCode,value);
      }},
    {label:"TVM编号",
      "prop":"tvmOrder",type:'select',search:true,searchslot:true},
    {label:"收入日期",
      "prop":"settleTime",search:true, type:"date",format:'yyyy-MM-dd',valueFormat:'yyyy-MM-dd'},
    {label:"支付方式",
      "prop":"payType",type:'select',dicData:getMappingStatusArray('xw_pay_type'),search:true,formatter:function (row,v) {
          return getMappingStatus('xw_pay_type',v);
      }},
      {label:"LC售卖金额",width:120,
      "prop":"saleAmount",formatter:function (row,value , label, column) {
        return fenExYuangettoFixed(row,'saleAmount');
      }},
      {label:"LC充值金额",width:120,
      "prop":"depositAmount",formatter:function (row,value , label, column) {
        return fenExYuangettoFixed(row,'depositAmount');
      }},
    {label:"LC退款金额",width:120,
      "prop":"errorRefundAmount",formatter:function (row,value , label, column) {
        return fenExYuangettoFixed(row,'errorRefundAmount');
      }},
    {label:"ACC售卖金额",width:120, "prop":"beSaleAmount",formatter:function (row,value , label, column) {
        return fenExYuangettoFixed(row,'beSaleAmount');
      }},
    {label:"ACC充值金额", width:120,"prop":"beDepositAmount",formatter:function (row,value , label, column) {
      return fenExYuangettoFixed(row,'beDepositAmount');
    }},
    {label:"ACC退款金额",width:120, "prop":"beErrorRefundAmount",formatter:function (row,value , label, column) {
        return fenExYuangettoFixed(row,'beErrorRefundAmount');
      }},
    {label:"充值差异金额",width:120, "prop":"chongzhichayi",formatter:function(row, value , label, column){
        let chaYi = getChaYi(row,'depositAmount','beDepositAmount');
        row.chongzhichayi=chaYi;
        return fenExYuangettoFixed(row,'chongzhichayi');
      }},
    {label:"售卖差异金额",width:120, "prop":"shoumaichayi",formatter:function(row, value , label, column){
        let chaYi = getChaYi(row,'saleAmount','beSaleAmount');
        row.shoumaichayi=chaYi;
        return fenExYuangettoFixed(row,'shoumaichayi');
      }},
    {label:"退款差异金额", width:120,"prop":"guzhangtuikuanchayi",formatter:function(row, value , label, column){
        let chaYi = getChaYi(row,'errorRefundAmount','beErrorRefundAmount');
        row.guzhangtuikuanchayi=chaYi;
        return fenExYuangettoFixed(row,'guzhangtuikuanchayi');
      }},
    {label:"回馈状态",
      "prop":"qfReplyStatus",type:'select',search:true,
      searchValue:0,//默认未回馈
      dicData:[{
        label: '未回馈',
        value: 0
      }, {
        label: '已回馈',
        value: 1
      }],
      formatter:function (row, value , label, column){
        return value == 1?'已回馈':'未回馈';
      },
    },
    // {label:"替换状态",
    //   "prop":"replaceStatus",type:'select',search:true,
    //   dicData:repalceStatus(),
    //   formatter:function (row, value , label, column){
    //     return getRepalceStatus(value);
    //   },
    // },
    {label:"通知时间",
      "prop":"sendAssistTime",formatter:function (row,v) {
        return moment(v).format("YYYY-MM-DD");
      }}
    //   {
    //   label: '充值差异金额',
    //   prop: 'comparativeInvestAmount',
    //   formatter:function (row,value , label, column) {
    //     let amount;
    //     if(row.payType==1){
    //       if(row.compareType==1){
    //         amount = ((row.lcCashRecharge-row.scCashRecharge)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accCashRecharge-row.lcCashRecharge)/100).toFixed(2);
    //       }
    //     }else{
    //       if(row.compareType==1){
    //         amount = ((row.lcElecRecharge-row.scElecRecharge)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accElecRecharge-row.lcElecRecharge)/100).toFixed(2);
    //       }
    //     }
    //     if(amount=='NaN')
    //       return '0.00';
    //     return amount;
    //   },
    //   search: false,
    //   hide: false,
    // },{
    //   label: '售票差异金额',
    //   prop: 'comparativeSelltkAmount',
    //   formatter:function (row,value , label, column) {
    //     let amount;
    //     if(row.payType==1){
    //       if(row.compareType==1){
    //         amount = ((row.lcCashSellTicket-row.scCashSellTicket)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accCashSellTicket-row.lcCashSellTicket)/100).toFixed(2);
    //       }
    //     }else{
    //       if(row.compareType==1){
    //         amount = ((row.lcElecSellTicket-row.scElecSellTicket)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accElecSellTicket-row.lcElecSellTicket)/100).toFixed(2);
    //       }
    //     }
    //     if(amount=='NaN')
    //       return '0.00';
    //     return amount;
    //   },
    //   search: false,
    //   hide: false,
    // },{
    //   label: '补票差异金额',
    //   prop: 'comparativeFaretkAmount',
    //   formatter:function (row,value , label, column) {
    //     let amount;
    //     if(row.payType==1){
    //       if(row.compareType==1){
    //         amount = ((row.lcCashReturn-row.scCashReturn)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accCashReturn-row.lcCashReturn)/100).toFixed(2);
    //       }
    //     }else{
    //       if(row.compareType==1){
    //         amount = ((row.lcElecReturn-row.scElecReturn)/100).toFixed(2);
    //       }else{
    //         amount = ((row.accElecReturn-row.lcElecReturn)/100).toFixed(2);
    //       }
    //     }
    //     if(amount=='NaN')
    //       return '0.00';
    //     return amount;
    //   },
    //   search: false,
    //   hide: false,
    // },{
    //   label: '差异类型',
    //   prop: 'compareType',
    //   formatter:function(row, value , label, column){
    //     row.$compareType=value == 3?'LC':'ACC';
    //     return value == 3?'LC':'ACC';
    //   },
    //   search: false,
    //   hide: false,
    // },
    // {label:"通知时间",search:true,type:'date',format:'yyyy-MM-dd',valueFormat:'yyyy-MM-dd',
    //   "prop":"sendAssistTime",formatter:function (row,v) {
    //     return moment(v).format("YYYY-MM-DD");
    //   }}, {
    //   label: '状态',
    //   prop: 'qfReplyStatus',
    //   search: true,
    //   type:'select',
    //   dicData:[{
    //     label: '已回馈',
    //     value: 1
    //   },{
    //     label: '未回馈',
    //     value: 0
    //   }],
    //   formatter:function(row, value , label, column) {
    //     return value==1?'已回馈':'未回馈';
    //   },
    //   hide: false
    // },{
    //   label: '归属清分回馈差异原因',
    //   prop: 'qfReplyReason',
    //   dicData:allStatus['QF_REPLY_REASON']
    // }
  ]
};

function getChaYi(row,compareFirst,compareSec){ //lc acc差额
  let first = getLcOrAccAmount('','',row[compareFirst]);//lc
  let sec = getLcOrAccAmount(row.compareType,4,row[compareSec]); //acc
  return first-sec;
}

function getLcOrAccAmount(originType,needType,thisData){ //lc-acc
  if((originType+"")==(needType+"")){
    return thisData;
  }else{
    return 0;
  }
}
